package com.walle.ak47.commons.jaxrs;

import com.walle.ak47.commons.jaxrs.constant.ServerCode;
import com.walle.ak47.commons.jaxrs.exception.BizException;

public final class RespUtils {

	public static <T extends BaseResp> T getSuccessResp(Class<T> type) {
		T t = null;
		try {
			t = (T) type.newInstance();
			t.setStatus(ServerCode.SUCESS.code());
			t.setReason(ServerCode.SUCESS.message());
		} catch (Exception e) {
			throw new BizException(ServerCode.SYSTEM_ERROR.code(), "系统获取成功响应实例失败，type=" + type.getName());
		}
		return t;
	}
	
	public static void throwSystemException(Throwable e) {
		throw new BizException(ServerCode.SYSTEM_ERROR.code(), ServerCode.SYSTEM_ERROR.message() + " : " + e.getMessage());
	}
	
}
